import JsDataStore  from './JsDataStore'

export class JsQtModule {

  moduleJsObjects : Object = null;

  constructor() {
    JsDataStore.addJsModule(this);
  }

  hasJsObjectType(type: string): boolean {
    if (this.moduleJsObjects == null)
      return false;
    const constructor = this.moduleJsObjects[type];
    return constructor != null;
  }

  createJsObjectImpl(type: string, ...args: any[]): Object {
    if (this.moduleJsObjects == null)
      return null;
    const constructor = this.moduleJsObjects[type];
    if (constructor) {
      return new constructor(...args);
    }
    return null;
  }

  createJsObject(type: string, name: string, ...args: any[]): Object {
    let obj = this.createJsObjectImpl(type, ...args);
    return obj;
  }
}